import { LiveData } from "../../framework/base/data/LiveData";
import { RegDataClass, RegPropertyOberver } from "../../framework/base/common/Decorator";
import { EventMgr } from "../../framework/base/event/EventMgr";
import { EEventTable } from "../../framework/base/const/BaseDefine";
import { IMessage } from "../../framework/base/message/IMessage";

class TestData1 extends LiveData {
    @RegPropertyOberver
    testVersion: number = -1;
}

/**
 * 测试属性值变化监听通知
 */
function test_1() {
    const d1 = new TestData1("test");
    d1.testVersion += 1;
    d1.testVersion += 1;
}

@RegDataClass("TestData2")
class TestData2 extends LiveData {
    @RegPropertyOberver
    testLevel: number = 0;
}

class TestData2Observer {
    data: TestData2;
    constructor() {
        EventMgr.getInstance().on(EEventTable.DATA_CHANGED, this.onDataChanged, this);

        this.data = new TestData2("TestData2");
    }

    changeData() {
        this.data.testLevel += 1;
    }

    onDataChanged(msg: IMessage) {
        console.log(msg);
    }
}

/**
 * 测试生命周期数据的属性值变化事件派发
 */
function test_2() {
    const ob = new TestData2Observer();
    ob.changeData();
    ob.changeData();
}

/**
 * 测试元数据类
 */
export function test_datameta() {
    console.log("===>Test: test_datameta()");
    // test_1();
    test_2();
}
